/**
 * Copyright © 2012, MIMOS, All Rights Reserved
 * 
 * Modification History:
 **********************************************************
 * Date            Author            Comments
 * 20121129        bp.ong          create new
 **********************************************************
 */
package jeesample.dtos;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.google.gson.Gson;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class DataTransferObject implements Serializable {

	public static final String STATUS_OK = "status:ok";
	public static final String STATUS_ERR = "status:error";

	@XmlElement(required = true)
	private String respondStatus;
	@XmlElement(required = true)
	private String respondMessage;

	public String getRespondStatus() {
		return respondStatus;
	}

	public void setRespondStatus(String respondStatus) {
		this.respondStatus = respondStatus;
	}

	public String getRespondMessage() {
		return respondMessage;
	}

	public void setRespondMessage(String respondMessage) {
		this.respondMessage = respondMessage;
	}

	public void prepOk() {
		respondStatus = "OK";
		respondMessage = "";
	}

	public DataTransferObject initAsOK() {
		DataTransferObject dto = getChildDTO();
		return dto;
	}

	public DataTransferObject initAsERR(String message) {
		DataTransferObject dto = getChildDTO();
		dto.setRespondStatus(STATUS_ERR);
		dto.setRespondMessage(message);
		return dto;
	}

	public String toString() {
		Gson gson = new Gson();
		return gson.toJson(this);
	}

	public abstract DataTransferObject getChildDTO();

}